<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>同步老广发网资讯</title>
    <link rel="stylesheet" type="text/css" href="../lib/ext/resources/css/ext-all-neptune.css"/>
    <script type="text/javascript" src="../lib/ext/ext-all.js"></script>
    <script type="text/javascript" src="../lib/gf/common_grid.js"></script>
    <script type="text/javascript" src="../lib/ext_ux_treepicker.js"></script>
</head>
<script type="text/javascript">
Ext.Loader.setConfig({enabled: true});

Ext.Loader.setPath('Ext.ux', '/ext4/ux/');
Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.util.*',
    'Ext.toolbar.Paging',
    'Ext.ModelManager',
    'Ext.tip.QuickTipManager'
]);

var win, uploadForm,_id,store;
Ext.onReady(function () {
	var myMask = new Ext.LoadMask(Ext.getBody(),{msg:"请稍等,正在导入..."}); 
    function sysArticle() {
        var params = uploadForm.form.getFieldValues();
        if(!params.category){
            alert('请选择导入的栏目');
            return;
        }
        if(!params.gf_category){
            alert('请选择要导入的老广发栏目');
            return;
        }
        params.category = Ext.getCmp("category").getPicker().selModel.getSelection()[0].getId();
        params.type_path = Ext.getCmp("category").getPicker().selModel.getSelection()[0].getPath() + "/";
        myMask.show();
        Ext.Ajax.request({
            url: '/article/import',
            params : params,
            method : 'POST',
            success: function(response, opts) {
            	if (myMask != undefined){ myMask.hide();}
                Ext.MessageBox.alert('消息提示', response.responseText);
            },
            failure: function(response, opts) {
            	if (myMask != undefined){ myMask.hide();}
                Ext.MessageBox.alert('消息提示', '同步成功！');
            }
        });
    }



    Ext.define( 'FileList', {
        extend: 'Ext.data.Model',
        fields: [
            '_id','file_name','file_id','file_size','upload_date'
        ],
        idProperty: '_id'
    });

    uploadForm = new Ext.FormPanel({
        labelWidth: 75, 
        xtype: 'form',
        region: 'center',
        height : 100,
        defaultType: 'textfield',
        layout: {
            type: 'table',
            columns: 1
        },
        items: [
        {
            xtype: 'treepicker',
            fieldLabel: '导入到指定栏目',
            lableAlign:'right',
            id: 'category',
            name : 'category',
            width: 400,
            displayField: 'text',
            valueField: 'id',
            minPickerHeight: 200,//默认最小高度
            cascade : 'child',//级联方式:1.child子级联(仅向下勾选子节点)；2.parent父级联(仅向上勾选父节点)；3.both全部级联(向上向下的父/子节点均会勾选)  
            checkModel:'single',//当json数据为不带checked的数据时只配置为single,带checked配置为double为单选,不配置为多选 
            store: Ext.create('Ext.data.TreeStore',{
                root: {
                  text: '全部',
                  expanded: true
                },
                proxy: {
                  type: 'ajax',
                  url: '/dict/tree_ext?parent_code=article_category',
                  // url: '/dict/tree_ext?parent_code=root',
                  reader: {
                    type: 'json'
                  }
                }
            })
        },{
        	xtype:'container',
        	layout: 'hbox',
        	items:[
        		{
		            xtype: 'combobox',
		            fieldLabel: '老广发网栏目',
		            lableAlign:'right',
		            id: "gf_category",
		            name: 'gf_category',
		            displayField: 'key_name',
		            valueField: 'key_code',
		            editable: false,
		            store: new Ext.data.JsonStore({
		                storeId: 'oldGfStore',
		                autoLoad: true,
		                proxy: {
		                    type: 'ajax',
		                    url: '/dict/list?parent_code=old_gfw_article',
		                    reader: {
		                        type: 'json',
		                        idProperty: 'key_code'
		                    }
		                },
		                fields: ['key_name', 'key_code']
		            })
		        },{
		        	xtype:'label',
		        	width: 20
		        },          
		        {
		            xtype : 'button',
		            icon: '../img/add.png',
		            text: "执行同步",
		            width : 100,
		            handler: sysArticle
		        }
        	]
        }]
    });


    var viewport = new Ext.Viewport({
        layout: 'border',
        renderTo: "topic-grid",
        items: [uploadForm]}
    );

    window.closeWin = function(){
        win.hide();
    }
});
</script>
<body>
<div id="topic-grid" style="height: 1024px;width:100%"></div>
</body>
</html>